<?php

// Copyright 2005, Google Inc. All rights reserved.

/**
 *  Show the error messages of a soap exception.
 *  Will also print the soap request and response.
 */
function showMyErrors($client) {
  // print the soap
  showRequestResponse($client);

  // print the error information
  echo '<h2>Fault Code</h2>' . "\n";
  echo "<b>Fault:</b>  {$client->fault}<br>\n";
  echo "<b>Code:</b> {$client->faultcode}<br>\n";
  echo "<b>String:</b> {$client->faultstring}<br>\n";
  echo "<b>Detail:</b> {$client->faultdetail}<br>\n";
}

/**
 * Show bad construction error message.
 */
function showSoapClientError($err) {
  echo '<h2>Soap Client Error</h2>' . "\n";
  echo '<pre>' . $err . '</pre>';
  echo "\n";
}

/**
 * Show calling method.
 */
function showCall($methodName, $param) {
  echo '<h2>Method Called</h2>';
  echo "<b>method:</b> $methodName<br>";
  echo '<b>param:</b> ' . toHtml($param) . "<br>\n";
}

/**
 *  Print soap request and response
 */
function showRequestResponse($client) {
  // print request
  echo '<h2>Request</h2>' . "\n";
  echo '<pre>' . toHtml($client->request) . '</pre>';
  echo "\n";

  // print response
  echo '<h2>Response</h2>'. "\n";
  echo '<pre>' . toHtml($client->response) . '</pre>';
  echo "\n";

  // Uncomment the following lines to print debug statements
  /*
  echo '<h2>Debug</h2>' . "\n";
  echo '<pre>' . toHtml($client->debug_str) . '</pre>';
  echo "\n";
  */
}

/**
 * Show the syn service id.
 */
function showSynServiceId($synServiceId) {
  echo '<h2>Service Id</h2>' . "\n";
  echo '<b>synServiceId:</b> ' . $synServiceId . "<br>\n";
}

/**
 * Print snippet
 */
function showSnippet($snippet) {
  echo '<h2>Snippet</h2>' . "\n";
  $text = toHtml($snippet, ENT_QUOTES);
  echo '<pre>' . $text . '</pre>';
  echo "\n";
}

/**
 *  Print the result of account creation
 */
function showCreatedPublisher($response) {
  echo '<h2>Created Publisher</h2>' . "\n";
  echo "<b>id:</b> " . $response['id'] . "<br>\n";
  echo "<b>type:</b> " . $response['type']['value'] . "<br>\n";
}

/**
 *  Get rid of the tag in html so it is displayable.
 */
function toHtml($text)
{
  $my_text = htmlspecialchars($text, ENT_QUOTES);
  $remove = array ("&lt;", " xmlns");
  $insert = array ("<br>&lt;", "<br>    xmlns");
  $my_text = str_replace($remove, $insert, $my_text);
  return $my_text;
}




?>

